package com.educate.device.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.device.model.bo.ChildDeviceBO;
import com.educate.device.rpc.api.ChildDeviceService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("childDevice")
public class ChildDeviceController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private ChildDeviceService childDeviceService;

    @PostMapping(value = "/create")
    public R create(@RequestBody ChildDeviceBO bo) {
        childDeviceService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody ChildDeviceBO bo) {
        childDeviceService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{childDeviceId}")
    public R delete(@PathVariable String childDeviceId) {
        childDeviceService.delete(childDeviceId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{childDeviceId}")
    public R<ChildDeviceBO> detail(@PathVariable String childDeviceId) {
        ChildDeviceBO bo = childDeviceService.detail(childDeviceId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<ChildDeviceBO> detail(@RequestBody ChildDeviceBO bo) {
        ChildDeviceBO detail = childDeviceService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<ChildDeviceBO> update(@RequestBody ChildDeviceBO bo) {
        childDeviceService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<ChildDeviceBO>> query(@RequestBody ChildDeviceBO bo) {
        Page<ChildDeviceBO> result = childDeviceService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<ChildDeviceBO>> list(@RequestBody ChildDeviceBO bo) {
        List<ChildDeviceBO> result = childDeviceService.list(bo);
        return R.ok(result);
    }

}
